// 跳格子
#include <cmath>
#include <iostream>
#include <vector>
#include <math.h>
#include <limits.h>
using namespace std;

void get_step(int i, vector<int> &a)
{
    for (int j = 2; j <= sqrt(i); j++)
    {
        if (i % j == 0)
        {
            a.push_back(j);
            if (i / j != j)
                a.push_back(i / j);
        }
    }
}

int get_minstep(int n, int m)
{
    vector<int> step;
    step.resize(m + 1, INT_MAX);
    step[n] = 0;
    for (int i = n; i < m; ++i)
    {
        if (step[i] == INT_MAX)
            continue;

        vector<int> a;
        get_step(i, a);

        for (int j = 0; j < a.size(); ++j)
        {
            if (i + a[j] <= m && step[i + a[j]] != INT_MAX)
            {
                step[i + a[j]] = step[i + a[j]] <= step[i] + 1 ? step[i + a[j]] : step[i] + 1;
            }
            else if (a[j] + i <= m)
            {
                step[i + a[j]] = step[i] + 1;
            }
        }
    }
    return step[m] == INT_MAX ? -1 : step[m];
}
int main()
{
    int n, m;
    int min_step = 0;
    while (cin >> n >> m)
    {
        min_step = get_minstep(n, m);
        cout << min_step << endl;
    }
    return 0;
}


//分割命令
#include <iostream>
#include <string>
#include<vector>
#include <cstring>
using namespace std;

int main() {
    string str;
    while(getline(cin,str))
    {
        vector<string> v;
        string s="";
        bool flag=0;
       for(int i=0;i<str.size();++i)
       {
        if(str[i]=='"')
        {
            flag=!flag;
        }
        else if(str[i]==' '&&flag==0)
        {
            v.push_back(s);
            s.clear();
        }
        else 
        {
          s+=str[i];
        }
       }
       v.push_back(s);

       cout<<v.size()<<endl;
       for(auto e:v)
       {
        cout<<e<<endl;
       }
    }
    return 0;
}